```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring AI 指南 - Java开发者的AI集成方案</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.8;
        }
        .heading {
            font-family: 'Noto Serif SC', Georgia, serif;
        }
        .section-title {
            position: relative;
            padding-bottom: 1rem;
        }
        .section-title:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 60px;
            height: 3px;
            background: linear-gradient(90deg, #4361ee, #3a0ca3);
            border-radius: 3px;
        }
        .code-block {
            background: #2d3748;
            color: #f8fafc;
            border-radius: 0.5rem;
            position: relative;
        }
        .code-block:before {
            content: attr(data-lang);
            position: absolute;
            top: 0;
            right: 1rem;
            background: #1a202c;
            color: #a0aec0;
            padding: 0.25rem 0.5rem;
            border-radius: 0 0 0.25rem 0.25rem;
            font-size: 0.75rem;
            text-transform: uppercase;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight-box {
            border-left: 4px solid #4361ee;
            background: rgba(67, 97, 238, 0.05);
        }
        .first-letter:first-letter {
            float: left;
            font-size: 4rem;
            line-height: 0.8;
            margin-right: 0.5rem;
            margin-top: 0.2rem;
            color: #4361ee;
            font-weight: 700;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <div class="relative bg-gradient-to-r from-blue-600 to-indigo-900 text-white py-24 px-6 sm:py-32 lg:px-8">
        <div class="absolute inset-0 bg-black opacity-30"></div>
        <div class="max-w-4xl mx-auto relative z-10 text-center">
            <div class="flex justify-center mb-4">
                <span class="inline-flex items-center rounded-full bg-white bg-opacity-10 px-4 py-2 text-sm font-medium">
                    <i class="fas fa-robot mr-2"></i> AI 集成指南
                </span>
            </div>
            <h1 class="heading text-4xl sm:text-6xl font-bold tracking-tight mb-6">
                Spring AI 全流程开发指南
            </h1>
            <p class="text-xl sm:text-2xl text-blue-100 max-w-3xl mx-auto">
                从零开始，掌握 Spring AI 核心组件，一小时内构建智能应用
            </p>
            <div class="mt-10 flex flex-col sm:flex-row justify-center gap-4">
                <a href="#getting-started" class="bg-white text-blue-600 px-8 py-3 rounded-lg font-semibold hover:bg-blue-50 transition duration-300 transform hover:-translate-y-1">
                    <i class="fas fa-rocket mr-2"></i> 快速开始
                </a>
                <a href="#rag-demo" class="bg-transparent border-2 border-white px-8 py-3 rounded-lg font-semibold hover:bg-white hover:bg-opacity-10 transition duration-300 transform hover:-translate-y-1">
                    <i class="fas fa-code mr-2"></i> 查看案例
                </a>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-7xl mx-auto px-6 py-12 sm:py-16 lg:px-8">
        <!-- Intro -->
        <div class="mb-20">
            <p class="first-letter text-lg sm:text-xl text-gray-700 mb-8 leading-relaxed">
                AI 已成为技术创新的主战场，作为 Java 开发者，如何快速将 AI 能力融入现有 SpringBoot 应用？Spring AI 作为 Spring 生态的最新成员，为开发者提供了与 OpenAI、Azure、Ollama 等多种 AI 服务集成的便捷方式。本文将从零开始，带你掌握 Spring AI 核心组件，实现从简单文本生成到复杂 RAG 应用的全流程开发。
            </p>
            <div class="flex flex-col sm:flex-row gap-6">
                <div class="flex-1 bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 p-3 rounded-full mr-4">
                            <i class="fas fa-bolt text-blue-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800">无需AI背景</h3>
                    </div>
                    <p class="text-gray-600">只要你熟悉 SpringBoot，无需深度学习知识，即可快速上手 AI 应用开发</p>
                </div>
                <div class="flex-1 bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-purple-100 p-3 rounded-full mr-4">
                            <i class="fas fa-plug text-purple-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800">多种模型支持</h3>
                    </div>
                    <p class="text-gray-600">轻松集成 OpenAI、Azure AI、Hugging Face 等多种 AI 服务</p>
                </div>
                <div class="flex-1 bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-green-100 p-3 rounded-full mr-4">
                            <i class="fas fa-layer-group text-green-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800">完整生态支持</h3>
                    </div>
                    <p class="text-gray-600">从模型接入到向量数据库，Spring AI 提供全栈解决方案</p>
                </div>
            </div>
        </div>

        <!-- Section 1 -->
        <div id="overview" class="mb-20">
            <h2 class="heading text-3xl font-bold text-gray-900 mb-8 section-title">1. Spring AI 生态概览</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-4">项目定位与发展历程</h3>
                    <p class="text-gray-700 mb-6">
                        Spring AI 是 Spring 团队于 2023 年推出的开源项目，旨在为 Java 开发者提供简单易用的 AI 集成能力。它遵循 Spring 一贯的"约定优于配置"理念，让开发者专注于业务逻辑而非底层实现。
                    </p>
                    
                    <h3 class="text-xl font-bold text-gray-800 mb-4">与其他AI框架对比</h3>
                    <p class="text-gray-700 mb-6">
                        相比 Langchain4j 等框架，Spring AI 的优势在于与 Spring 生态的无缝集成，提供了更加符合 Java 开发者习惯的编程模型。
                    </p>
                </div>
                <div>
                    <div class="code-block p-6 overflow-x-auto" data-lang="java">
                        <pre><code class="text-sm">// Spring AI方式
@Service
public class AIService {
    @Autowired
    private ChatClient chatClient;
    
    public String generateResponse(String prompt) {
        return chatClient.call(prompt);
    }
}</code></pre>
                    </div>
                </div>
            </div>

            <h3 class="text-xl font-bold text-gray-800 mb-4">核心模块与功能地图</h3>
            <div class="highlight-box p-6 rounded-lg mb-8">
                <p class="text-gray-700">Spring AI 提供了多个核心模块，包括模型接入、提示词管理、嵌入计算、向量存储等：</p>
                <ul class="list-disc pl-6 mt-4 space-y-2 text-gray-700">
                    <li><span class="font-semibold">spring-ai-core</span>: 核心抽象和接口</li>
                    <li><span class="font-semibold">spring-ai-openai</span>: OpenAI 集成</li>
                    <li><span class="font-semibold">spring-ai-bedrock</span>: AWS Bedrock 集成</li>
                    <li><span class="font-semibold">spring-ai-vertex</span>: Google Vertex AI 集成</li>
                </ul>
            </div>

            <div class="bg-white rounded-xl shadow-md overflow-hidden p-6">
                <div class="mermaid">
                    graph TD
                        A[Spring AI] --> B[模型接入]
                        A --> C[提示工程]
                        A --> D[嵌入计算]
                        A --> E[向量存储]
                        B --> B1[OpenAI]
                        B --> B2[Azure AI]
                        B --> B3[Hugging Face]
                        C --> C1[PromptTemplate]
                        C --> C2[系统提示]
                        C --> C3[上下文管理]
                        D --> D1[文本向量化]
                        D --> D2[相似度计算]
                        E --> E1[Redis]
                        E --> E2[PostgreSQL]
                        E --> E3[Weaviate]
                </div>
            </div>
        </div>

        <!-- Section 2 -->
        <div id="getting-started" class="mb-20">
            <h2 class="heading text-3xl font-bold text-gray-900 mb-8 section-title">2. 环境搭建与项目配置</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-4">Maven/Gradle 依赖配置</h3>
                    
                    <div class="code-block p-6 overflow-x-auto mb-6" data-lang="xml">
                        <pre><code class="text-sm">&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.ai&lt;/groupId&gt;
    &lt;artifactId&gt;spring-ai-openai-spring-boot-starter&lt;/artifactId&gt;
    &lt;version&gt;1.0.0-M5&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
                    </div>
                    
                    <div class="code-block p-6 overflow-x-auto" data-lang="groovy">
                        <pre><code class="text-sm">implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter:0.8.0'</code></pre>
                    </div>
                </div>
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-4">API 密钥管理</h3>
                    <div class="code-block p-6 overflow-x-auto" data-lang="yaml">
                        <pre><code class="text-sm"># application.yml
spring:
  ai:
    openai:
      api-key: ${OPENAI_API_KEY}
      base-url: https://api.openai.com
      model: gpt-3.5-turbo</code></pre>
                    </div>
                </div>
            </div>
            
            <h3 class="text-xl font-bold text-gray-800 mb-4">基础配置类编写</h3>
            <div class="code-block p-6 overflow-x-auto mb-8" data-lang="java">
                <pre><code class="text-sm">@Configuration
public class AIConfig {
    @Bean
    public ChatClient openAIChatClient(OpenAiChatProperties properties) {
        return new OpenAiChatClient(properties);
    }
}</code></pre>
            </div>
            
            <h3 class="text-xl font-bold text-gray-800 mb-4">常见启动问题排查</h3>
            <div class="highlight-box p-6 rounded-lg">
                <p class="text-gray-700 mb-4">如遇连接超时问题，可配置代理：</p>
                <div class="code-block p-6 overflow-x-auto" data-lang="yaml">
                    <pre><code class="text-sm">spring:
  ai:
    openai:
      http-client:
        proxy:
          host: your-proxy-host
          port: 8080</code></pre>
                </div>
            </div>
        </div>

        <!-- Section 3 -->
        <div class="mb-20">
            <h2 class="heading text-3xl font-bold text-gray-900 mb-8 section-title">3. 模型接入与管理</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-4">OpenAI 模型集成</h3>
                    <div class="code-block p-6 overflow-x-auto" data-lang="java">
                        <pre><code class="text-sm">@RestController
@RequestMapping("/api/chat")
public class ChatController {
    
    private final ChatClient chatClient;
    
    public ChatController(ChatClient chatClient) {
        this.chatClient = chatClient;
    }
    
    @PostMapping
    public String chat(@RequestBody String message) {
        Prompt prompt = new Prompt(message);
        ChatResponse response = chatClient.call(prompt);
        return response.getResult().getOutput().getContent();
    }
}</code></pre>
                    </div>
                </div>
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-4">国产大模型接入</h3>
                    <div class="code-block p-6 overflow-x-auto" data-lang="java">
                        <pre><code class="text-sm">@Configuration
public class WenxinAdapter implements ChatClient {
    // 实现相关接口方法
    // 对接文心一言API
}</code></pre>
                    </div>
                </div>
            </div>
            
            <h3 class="text-xl font-bold text-gray-800 mb-4">模型参数调优技巧</h3>
            <div class="code-block p-6 overflow-x-auto mb-8" data-lang="java">
                <pre><code class="text-sm">ChatOptions options = ChatOptions.builder()
    .temperature(0.7f)
    .topP(0.95f)
    .maxTokens(500)
    .build();

Prompt prompt = new Prompt(userMessage, options);</code></pre>
            </div>
            
            <h3 class="text-xl font-bold text-gray-800 mb-4">多模型策略</h3>
            <div class="code-block p-6 overflow-x-auto" data-lang="java">
                <pre><code class="text-sm">@Service
public class ModelSelectorService {
    private final Map&lt;String, ChatClient&gt; models;
    
    public ModelSelectorService(List&lt;ChatClient&gt; clients) {
        this.models = clients.stream()
            .collect(Collectors.toMap(
                client -> client.getClass().getSimpleName(),
                client -> client
            ));
    }
    
    public ChatClient selectModel(String task) {
        if (task.contains("创意")) {
            return models.get("OpenAiChatClient");
        } else {
            return models.get("WenxinChatClient");
        }
    }
}</code></pre>
            </div>
        </div>

        <!-- Section 4 -->
        <div class="mb-20">
            <h2 class="heading text-3xl font-bold text-gray-900 mb-8 section-title">4. 提示词工程实战</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-4">Prompt 核心概念</h3>
                    <div class="code-block p-6 overflow-x-auto" data-lang="java">
                        <pre><code class="text-sm">String systemMessage = "你是一位专业的Java技术顾问，精通SpringBoot。";
String userMessage = "如何优化SpringBoot应用性能？";</code></pre>
                    </div>
                </div>
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-4">PromptTemplate 使用</h3>
                    <div class="code-block p-6 overflow-x-auto" data-lang="java">
                        <pre><code class="text-sm">String template = "我正在开发{framework}应用，遇到了{problem}问题，请提供解决方案。";
PromptTemplate promptTemplate = new PromptTemplate(template);
Map&lt;String, Object&gt; params = Map.of(
    "framework", "SpringBoot",
    "problem", "连接池溢出"
);
Prompt prompt = promptTemplate.create(params);</code></pre>
                    </div>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-4">系统与用户提示分离</h3>
                    <div class="code-block p-6 overflow-x-auto" data-lang="java">
                        <pre><code class="text-sm">SystemPrompt systemPrompt = new SystemPrompt("你是一位经验丰富的Java架构师");
UserPrompt userPrompt = new UserPrompt("请评审以下代码并提出改进建议：" + code);

ChatOptions options = ChatOptions.builder().build();
Prompt prompt = new Prompt(List.of(systemPrompt, userPrompt), options);</code></pre>
                    </div>
                </div>
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-4">变量注入与上下文管理</h3>
                    <div class="code-block p-6 overflow-x-auto" data-lang="java">
                        <pre><code class="text-sm">List&lt;Message&gt; history = new ArrayList&lt;&gt;();
history.add(new SystemMessage("你是助手"));
history.add(new UserMessage("Spring AI是什么?"));
history.add(new AssistantMessage("Spring AI是Spring生态中的AI集成框架..."));

// 新问题
UserMessage newQuestion = new UserMessage("它支持哪些模型?");
history.add(newQuestion);

Prompt prompt = new Prompt(history);</code></pre>
                    </div>
                </div>
            </div>
        </div>

        <!-- Section 5 -->
        <div class="mb-20">
            <h2 class="heading text-3xl font-bold text-gray-900 mb-8 section-title">5. 向量数据库集成</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-4">Redis 作为向量库</h3>
                    <div class="code-block p-6 overflow-x-auto" data-lang="yaml">
                        <pre><code class="text-sm">spring:
  ai:
    vectorstore:
      redis:
        host: localhost
        port: 6379</code></pre>
                    </div>
                    <div class="code-block p-6 overflow-x-auto mt-4" data-lang="java">
                        <pre><code class="text-sm">@Bean
public VectorStore redisVectorStore(RedisConnection connection, EmbeddingClient embeddingClient) {
    return new RedisVectorStore(connection, embeddingClient);
}</code></pre>
                    </div>
                </div>
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-4">文档加载与处理</h3>
                    <div class="code-block p-6 overflow-x-auto" data-lang="java">
                        <pre><code class="text-sm">@Service
public class DocumentService {
    private final VectorStore vectorStore;
    private final EmbeddingClient embeddingClient;
    
    // 构造函数注入
    
    public void loadDocuments(List&lt;String&gt; filePaths) {
        List&lt;Document&gt; documents = new ArrayList&lt;&gt;();
        
        for (String path : filePaths) {
            File file = new File(path);
            String content = Files.readString(file.toPath());
            Document doc = new Document(content, Map.of("source", path));
            documents.add(doc);
        }
        
        vectorStore.add(documents);
    }
}</code></pre>
                    </div>
                </div>
            </div>
            
            <h3 class="text-xl font-bold text-gray-800 mb-4">向量存储服务配置</h3>
            <div class="code-block p-6 overflow-x-auto mb-8" data-lang="java">
                <pre><code class="text-sm">@Configuration
public class VectorStoreConfig {
    @Bean
    public VectorStoreProperties vectorStoreProperties() {
        VectorStoreProperties props = new VectorStoreProperties();
        props.setDimensions(1536); // OpenAI嵌入维度
        props.setSimilarityFunction("cosine");
        return props;
    }
}</code></pre>
            </div>
            
            <h3 class="text-xl font-bold text-gray-800 mb-4">近似搜索实现</h3>
            <div class="code-block p-6 overflow-x-auto" data-lang="java">
                <pre><code class="text-sm">@GetMapping("/search")
public List&lt;Document&gt; search(@RequestParam String query, @RequestParam int k) {
    List&lt;Document&gt; results = vectorStore.similaritySearch(query, k);
    return results;
}</code></pre>
            </div>
        </div>

        <!-- Section 6 -->
        <div id="rag-demo" class="mb-20">
            <h2 class="heading text-3xl font-bold text-gray-900 mb-8 section-title">6. RAG 应用构建</h2>
            
            <div class="bg-blue-50 rounded-xl p-6 mb-8">
                <h3 class="text-xl font-bold text-gray-800 mb-4">RAG (检索增强生成) 架构</h3>
                <ol class="list-decimal pl-6 space-y-2 text-gray-700">
                    <li>文档嵌入并存储</li>
                    <li>用户查询转换为嵌入向量</li>
                    <li>相似度搜索找到相关文档</li>
                    <li>将文档内容与用户查询一起发送给LLM</li>
                </ol>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-4">文档嵌入流程实现</h3>
                    <div class="code-block p-6 overflow-x-auto" data-lang="java">
                        <pre><code class="text-sm">@Service
public class EmbeddingService {
    private final EmbeddingClient embeddingClient;
    
    public EmbeddingService(EmbeddingClient embeddingClient) {
        this.embeddingClient = embeddingClient;
    }
    
    public List&lt;List&lt;Double&gt;&gt; embedDocuments(List&lt;Document&gt; documents) {
        List&lt;String&gt; texts = documents.stream()
            .map(Document::getContent)
            .collect(Collectors.toList());
        
        EmbeddingResponse response = embeddingClient.embedForResponse(texts);
        return response.getResults().stream()
            .map(EmbeddingResponseData::getOutput)
            .collect(Collectors.toList());
    }
}</code></pre>
                    </div>
                </div>
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-4">检索增强生成核心代码</h3>
                    <div class="code-block p-6 overflow-x-auto" data-lang="java">
                        <pre><code class="text-sm">@Service
public class RAGService {
    private final VectorStore vectorStore;
    private final ChatClient chatClient;
    
    // 构造函数
    
    public String askWithContext(String question, int k) {
        // 1. 检索相关文档
        List&lt;Document&gt; relevantDocs = vectorStore.similaritySearch(question, k);
        
        // 2. 构建上下文提示词
        StringBuilder context = new StringBuilder();
        for (Document doc : relevantDocs) {
            context.append(doc.getContent()).append("\n\n");
        }
        
        // 3. 构建最终提示词
        String promptText = String.format(
            "基于以下信息回答问题:\n\n%s\n\n问题: %s",
            context.toString(),
            question
        );
        
        // 4. 调用LLM生成回答
        Prompt prompt = new Prompt(promptText);
        ChatResponse response = chatClient.call(prompt);
        
        return response.getResult().getOutput().getContent();
    }
}</code></pre>
                    </div>
                </div>
            </div>
            
            <h3 class="text-xl font-bold text-gray-800 mb-4">结果评估与优化</h3>
            <div class="code-block p-6 overflow-x-auto" data-lang="java">
                <pre><code class="text-sm">@Service
public class EvaluationService {
    private final ChatClient evaluatorClient;
    
    public double evaluateAnswer(String question, String answer, List&lt;Document&gt; sources) {
        String prompt = String.format(
            "评估以下回答的准确性和相关性，给出0-10分:\n问题: %s\n回答: %s\n参考资料: %s",
            question,
            answer,
            sources.stream().map(Document::getContent).collect(Collectors.joining("\n"))
        );
        
        String evaluation = evaluatorClient.call(new Prompt(prompt))
            .getResult().getOutput().getContent();
        
        // 解析评分
        Pattern pattern = Pattern.compile("\\d+");
        Matcher matcher = pattern.matcher(evaluation);
        if (matcher.find()) {
            return Double.parseDouble(matcher.group()) / 10.0;
        }
        return 0.0;
    }
}</code></pre>
            </div>
        </div>

        <!-- Section 7 -->
        <div class="mb-20">
            <h2 class="heading text-3xl font-bold text-gray-900 mb-8 section-title">7. 实用案例</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 p-3 rounded-full mr-4">
                                <i class="fas fa-headset text-indigo-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">AI 驱动的客服机器人</h3>
                        </div>
                        <div class="code-block p-6 overflow-x-auto" data-lang="java">
                            <pre><code class="text-sm">@Service
public class CustomerSupportBot {
    private final ChatClient chatClient;
    private final VectorStore knowledgeBase;
    
    public String handleCustomerQuery(String query) {
        // 1. 检索相关知识
        List&lt;Document&gt; relevantDocs = knowledgeBase.similaritySearch(query, 3);
        
        // 2. 构建提示词
        SystemPrompt systemPrompt = new SystemPrompt(
            "你是一位专业的客服代表，负责回答客户关于我们产品的问题。" +
            "使用以下知识库信息回答，如果不确定，请说明你需要更多信息。"
        );
        
        UserPrompt userPrompt = new UserPrompt(
            "知识库:\n" + relevantDocs.stream()
                .map(Document::getContent)
                .collect(Collectors.joining("\n\n")) +
            "\n\n客户问题: " + query
        );
        
        // 3. 获取回答
        Prompt prompt = new Prompt(List.of(systemPrompt, userPrompt));
        return chatClient.call(prompt)
            .getResult().getOutput().getContent();
    }
}</code></pre>
                        </div>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="bg-green-100 p-3 rounded-full mr-4">
                                <i class="fas fa-file-alt text-green-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">智能文档分析系统</h3>
                        </div>
                        <div class="code-block p-6 overflow-x-auto" data-lang="java">
                            <pre><code class="text-sm">@Service
public class DocumentAnalyzer {
    private final ChatClient chatClient;
    
    public DocumentSummary analyze(String document) {
        String promptText = String.format(
            "分析以下文档，提取关键信息，生成摘要，并列出重要实体:\n\n%s",
            document
        );
        
        Prompt prompt = new Prompt(promptText);
        String analysis = chatClient.call(prompt)
            .getResult().getOutput().getContent();
        
        // 解析分析结果
        return parseAnalysisResult(analysis);
    }
    
    private DocumentSummary parseAnalysisResult(String analysis) {
        // 解析逻辑
        return new DocumentSummary(/* 解析后的数据 */);
    }
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="bg-yellow-100 p-3 rounded-full mr-4">
                                <i class="fas fa-code text-yellow-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">代码助手实现</h3>
                        </div>
                        <div class="code-block p-6 overflow-x-auto" data-lang="java">
                            <pre><code class="text-sm">@Service
public class CodeAssistantService {
    private final ChatClient chatClient;
    
    public String generateCode(String description, String language) {
        SystemPrompt systemPrompt = new SystemPrompt(
            "你是一位专业的软件开发者，精通多种编程语言。" +
            "请根据描述生成高质量、符合最佳实践的代码。"
        );
        
        UserPrompt userPrompt = new UserPrompt(
            String.format("使用%s编写代码实现以下功能:\n%s", language, description)
        );
        
        Prompt prompt = new Prompt(List.of(systemPrompt, userPrompt));
        return chatClient.call(prompt)
            .getResult().getOutput().getContent();
    }
}</code></pre>
                        </div>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="bg-red-100 p-3 rounded-full mr-4">
                                <i class="fas fa-tachometer-alt text-red-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">性能优化与成本控制</h3>
                        </div>
                        <div class="code-block p-6 overflow-x-auto" data-lang="java">
                            <pre><code class="text-sm">@Configuration
@EnableCaching
public class AICacheConfig {
    
    @Bean
    public CacheManager cacheManager() {
        return new ConcurrentMapCacheManager("aiResponses");
    }
    
    @Service
    public static class CachedAIService {
        private final ChatClient chatClient;
        
        public CachedAIService(ChatClient chatClient) {
            this.chatClient = chatClient;
        }
        
        @Cacheable(value = "aiResponses", key = "#prompt.hashCode()")
        public String getResponse(Prompt prompt) {
            return chatClient.call(prompt)
                .getResult().getOutput().getContent();
        }
    }
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Conclusion -->
        <div class="bg-gradient-to-r from-blue-50 to-indigo-50 rounded-xl p-8 md:p-12">
            <h2 class="heading text-3xl font-bold text-gray-900 mb-6">总结</h2>
            <p class="text-lg text-gray-700 leading-relaxed mb-6">
                通过 Spring AI，Java 开发者可以轻松将 AI 能力融入 SpringBoot 应用，实现智能交互、文档处理和代码生成等多种场景。随着 Spring AI 的不断发展，我们可以期待更多便捷的 AI 集成能力，让 AI 应用开发变得更加简单高效。
            </p>
            <div class="flex flex-wrap gap-4">
                <span class="inline-flex items-center px-4 py-2 rounded-full bg-blue-100 text-blue-800 text-sm font-medium">
                    <i class="fas fa-check-circle mr-2"></i> 简单集成
                </span>
                <span class="inline-flex items-center px-4 py-2 rounded-full bg-purple-100 text-purple-800 text-sm font-medium">
                    <i class="fas fa-bolt mr-2"></i> 高效开发
                </span>
                <span class="inline-flex items-center px-4 py-2 rounded-full bg-green-100 text-green-800 text-sm font-medium">
                    <i class="fas fa-layer-group mr-2"></i> 全栈支持
                </span>
                <span class="inline-flex items-center px-4 py-2 rounded-full bg-indigo-100 text-indigo-800 text-sm font-medium">
                    <i class="fas fa-infinity mr-2"></i> 无限可能
                </span>
            </div>
        </div>
    </div>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```